package com.motong.gongdan.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "设备状态记录")
@Accessors(chain = true)
@Data
@TableName(value = "device_status")
public class DeviceStatus extends PublicPo implements Serializable {
    @TableId(value = "id", type = IdType.AUTO)
    @ApiModelProperty(value = "")
    private Long id;

    /**
     * 设备id
     */
    @TableField(value = "device_id")
    @ApiModelProperty(value = "设备id")
    private Long deviceId;

    /**
     * 状态(0 关机, 1 运行, 2 等待, 3 故障,4 离线)
     */
    @TableField(value = "`status`")
    @ApiModelProperty(value = "状态(0 关机, 1 运行, 2 等待, 3 故障,4 离线)")
    private Integer status;


    /**
     * 类型名称
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "状态名称")
    private String statusName;

    /**
     * 持续时间(分钟)
     */
    @TableField(value = "duration")
    @ApiModelProperty(value = "持续时间(分钟)")
    private Long duration;

    /**
     * 是否已上报异常(0 否， 1 是)
     */
    @TableField(value = "report_exception")
    @ApiModelProperty(value = "是否已上报异常(0 否， 1 是)")
    private Integer reportException;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    /**
     * 创建时间
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "开始时间戳")
    private Long createTimestamp;


    /**
     * 结束时间
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    public DeviceStatus setStatus(Integer status) {
        switch (status) {
            case 0:
                this.statusName = "关机";
                break;
            case 1:
                this.statusName = "运行";
                break;
            case 2:
                this.statusName = "等待";
                break;
            case 3:
                this.statusName = "故障";
                break;
            case 4:
                this.statusName = "离线";
                break;
        }

        this.status = status;
        return this;
    }

    private static final long serialVersionUID = 1L;
}